#ifndef _FramePool_H_
#define _FramePool_H_

#include <interfacelib/frame/frame.h>
#include <utillib/stl/Map.h>
#include <interfacelib/frame/handlemanager.h>

#pragma comment ( lib, "winmm.lib" )

namespace interfacelib
{
	namespace Frame
	{
		class FramePool
		{
		private:
			struct FramePreRelease
			{ 
				bool operator()( Frame *frame ) const 
				{
					if ( frame )
						frame->preRelease();

					return ( true );
				} 
			};
		protected:
			FramePool();
		public:
			virtual ~FramePool();

			void initialize( HINSTANCE windowInstance, HWND windowHandle );
			void release();

			void preRelease();

			void mouseEvent( WPARAM wparam, LPARAM lparam ){ if ( m_currentFrame ) m_currentFrame->mouseEvent( wparam, lparam ); };
			void editEvent( WPARAM wparam, LPARAM lparam ){ if ( m_currentFrame ) m_currentFrame->editEvent( wparam, lparam ); };
			
			bool addFrame( int frameIndex, interfacelib::Frame::Frame *frame );
			interfacelib::Frame::Frame* getCurrentFrame(){ return ( m_currentFrame ) ; };
			interfacelib::Frame::Frame *getFrame( int frame );

			void changePreviousFrame();

			interfacelib::Frame::Frame *changeFrame( int frame );
			bool changeFrame( interfacelib::Frame::Frame *frame );

			virtual void preTranslateMessage( MSG *msg );

			void terminateProcess(){ POSTMESSAGE( WM_DESTROY, 0 , 0 ); };

			void setServerTime( DWORD time );
			DWORD serverTimeToClientTime( DWORD time );
			DWORD getClientTime();
		public:
			virtual bool updateFrame();
			virtual bool drawFrame();

			bool syncTimeAck( netlib::net::TCPSocket *socket, DWORD serverTime );
		protected:
			virtual void onResetDevice();
		protected:
			DWORD m_serverTime;
			DWORD m_clientTime;

			Frame *m_currentFrame;

			utillib::stl::MapWithInteger < Frame * > m_frameList;

		};
	}
}
#endif